/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mobiubiq.directory.client.frame;

import org.kalmeo.kuix.core.Kuix;
import org.kalmeo.kuix.core.KuixMIDlet;
import org.kalmeo.kuix.widget.Desktop;
import org.kalmeo.kuix.widget.List;
import org.kalmeo.kuix.widget.ListItem;
import org.kalmeo.kuix.widget.Widget;
import org.mobiubiq.directory.client.data.ServiceSettingsDataProvider;
import org.mobiubiq.directory.client.data.ServiceSettingsRecordStore;

/**
 *
 * @author Marnix Renne
 */
public class Settings extends DataProviderBaseFrame {

    private ListItem selected;

    public Settings() {
        super("settings.xml", new ServiceSettingsDataProvider());
    }

    public boolean onMessage(Object identifier, Object[] arguments) {
        boolean result = super.onMessage(identifier, arguments);
        if (result) {
            if ("delete".equals(identifier)) {
                ServiceSettingsRecordStore.removeSettings(selected.getDataProvider().getStringValue("id"));
                List settingsList = (List) Kuix.getCanvas().getDesktop().getWidget("settingsList");
                settingsList.removeItem(selected.getDataProvider());
                result = false;
            }
            if ("select".equals(identifier)) {
                selected = (ListItem) arguments[0];
                result = false;
            //selected = item.getDataProvider();
            }
        }
        return result;
    }

    public void onAdded() {
        super.onAdded();
        ServiceSettingsDataProvider dataProvider = (ServiceSettingsDataProvider) this.getDataProvider();
        Desktop desktop = Kuix.getCanvas().getDesktop();
        Widget container = null;
        if(dataProvider.countItemValues(ServiceSettingsDataProvider.SETTINGS) > 0) {
            container = desktop.getWidget("settings");
        } else {
            container = desktop.getWidget("noSettingsAvailable");
        }
        container.setVisible(true);
    }
    
}
